package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.domain.customer.CustomerDO;
import com.qk.dto.customer.CustomerDTO;
import com.qk.dto.customer.UpdateCustomerDTO;
import com.qk.management.service.CustomerService;
import com.qk.vo.customer.CustomerListVO;
import com.qk.vo.customer.CustomerVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: Enid
 * @date: 2025/10/20 13:35
 * @description:
 */
@RestController
@RequestMapping("/customers")
public class CustomerController {
    @Autowired
    private CustomerService customerService;

    @PutMapping
    public Result update(@RequestBody UpdateCustomerDTO dto){
        customerService.updateCustomer(dto);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result selectById(@PathVariable("id") Integer id){
        CustomerListVO vo = customerService.selectById(id);
        return Result.success(vo);
    }

    /**
     * 添加客户
     */
    @PostMapping
    public Result add(@RequestBody CustomerDO customerDO) {
        customerService.insert(customerDO);
        return Result.success();
    }
    @GetMapping
    public Result list(CustomerDTO dto) {
        PageResult<CustomerVO> pageResult = customerService.pageList(dto);
        return Result.success(pageResult);
    }
}
